<?php
	Class Employee_controller extends CI_Controller{

		public function __construct(){
			parent::__construct();
			$this->load->model('employee_model');
		}
		public function index(){
			$list = $this->employee_model->listAll();
			if($list != null){
				$data['list'] = $list;
				$data['pageTitle'] = 'Employees';
				$data['page'] = 'employee_listAll_view';
				$this->load->view('/template/template', $data);
			}else{
				$data['message'] = 'No data found!';
				$data['pageTitle'] = 'Employees';
				$this->load->view('/template/template', $data);
			}			
		}
		public function add(){
			$data['pageTitle']= "Add";
			$data['page'] = 'employee_add_view';
			$this->load->view('/template/template', $data);
		}
		public function addThis(){
			$rules = array(
				array('field'=>'name','label'=>'Full name','rules'=>'required'),
				array('field'=>'address','label'=>'Country','rules'=>'required'),
				array('field'=>'email','label'=>'Email','rules'=>'required'),
				
			);
			$this->form_validation->set_rules($rules);
			if($this->form_validation->run() == FALSE){
				$data['pageTitle']= "Add";
				$data['page'] = 'employee_add_view';
				$this->load->view('/template/template', $data);
			}else{
				$values = array(
					'name'=>$this->input->post('name'),
					'address'=>$this->input->post('address'),
					'email'=>$this->input->post('email'),
					'status'=>'Y',
				);
				$result = $this->employee_model->addThis($values);
				if($result>0){
					redirect(base_url());
				}
			}
		}
		public function editThis($id){
			$listThis = $this->employee_model->listThis($id);
			$data['listThis'] = $listThis;
			$data['pageTitle'] = 'Edit';
			$data['page'] = 'employee_edit_view';
			$this->load->view('/template/template', $data);
		}
		public function update(){
			$status = $this->employee_model->updateThis($this->input->post('id'));
			if($status > 0){
				$data['message'] = 'update complete.';
				$data['list'] = $this->employee_model->listThis($this->input->post('id'));
			}else{
				$data['message'] = 'update error.';
				$data['list'] = 0;
			}
			$data['pageTitle'] = 'Update';
			redirect(base_url());
		}
		public function fireThis($id){
			$status = $this->employee_model->fire($id);
			redirect(base_url());
		}
	}
?>